import Request from '../http/Request'
import {
  // 滑块图片请求地址
  SWIPER,
  SWIPER2,
  RECOMMENT,
  LIST,
  CARTOON,
  DETAIL
} from '../config/uri'

// 数据模型，获取数据和数据处理
class IndexModel extends Request {

  /**
   * 返回Promise
   */
  getSwiper() {
    return this.get(SWIPER)
  }
  getSwiper2() {
    return this.get(SWIPER2)
  }
  //今日推荐
  async getRecommend( page = 0 ) {
    let data = await this.get(RECOMMENT)
    data = data.data.data.slice( page , page + 6 )
    // console.log(data);
    return Promise.resolve(data)
    
  }

  //榜单
  getList() {
    return this.get(LIST)
  }

   //世界
   getRecommend2() {
    return this.get(RECOMMENT)
  }
  //追漫
  getCartoon() {
    return this.get(CARTOON)
  }
  //详情
  getDetail() {
    return this.get(DETAIL)
  }
  //书架
  async getDetail2(id) {
    let data = await this.get(DETAIL)
    let newdata = data.data.data
    let newdata2 = newdata.filter(item => item.id == id)
    return Promise.resolve(newdata2[0])
  }
  //搜索
  async getSearch(sj=''){
    let ret= await this.get(CARTOON)
    let data=ret.data.data
    var newData=data.filter(val=>
     val.name==sj)
    return Promise.resolve(newData)
  }
}

export default new IndexModel